package com.thinksns.sociax.t4.android.findpeople;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.thinksns.sociax.android.R;
import com.thinksns.sociax.t4.adapter.AdapterSociaxList;
import com.thinksns.sociax.t4.android.Thinksns;
import com.thinksns.sociax.t4.android.fragment.FragmentSociax;
import com.thinksns.sociax.t4.android.user.ActivityUserInfo_2;
import com.thinksns.sociax.t4.android.video.ToastUtils;
import com.thinksns.sociax.t4.model.ModelSearchUser;
import com.thinksns.sociax.t4.model.ModelUser;
import com.thinksns.sociax.thinksnsbase.bean.ListData;
import com.thinksns.sociax.thinksnsbase.bean.SociaxItem;

/**
 * Created by Administrator on 2016/10/21.
 */

public class SexNearFragment extends FragmentSociax {
    private int style;
    @Override
    public int getLayoutId() {
        return  R.layout.fragment_chat_userlist;
    }

    @Override
    public void initView() {
        listView = (ListView) findViewById(R.id.pull_refresh_list);
        listView.setDivider(new ColorDrawable(getResources().getColor(R.color.bg_ios)));
        listView.setDividerHeight(1);
        listView.setSelector(getResources().getDrawable(R.drawable.listitem_selector));

        adapter = createAdapter();
        listView.setAdapter(adapter);
    }

    @Override
    public AdapterSociaxList createAdapter() {
        list = new ListData<SociaxItem>();
        return new AdapterFindPeopleBySex(this, list, getActivity()
                .getIntent().getIntExtra("uid", Thinksns.getMy().getUid()),
                style);
    }
    @Override
    public void initIntentData() {
        if (getActivity().getIntent().hasExtra("style")) {
            style = getActivity().getIntent().getIntExtra("style", 0);
        }
    }

    @Override
    public void initListener() {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ModelSearchUser user = (ModelSearchUser) adapter.getItem((int) id);
                if (Thinksns.getMy().getUid() != user.getUid() && ModelUser.CAN_NOT_TO_HOME == user.getSpace_privacy()) {
                    ToastUtils.showToast(R.string.tip_no_oauth_to_other_home);
                }else {
                    Intent intent = new Intent(getActivity(), ActivityUserInfo_2.class);
                    intent.putExtra("uid", user.getUid());
                    startActivity(intent);
                }
            }
        });
    }

    @Override
    public void initData() {
        adapter.loadInitData();
    }


}
